﻿#region using
using System;
using System.Collections.Generic;
#endregion using

namespace PdbRestorer
{
    class CommandLineArguments
    {
        Dictionary<string,List<string>> _args=new Dictionary<string,List<string>>();

        internal CommandLineArguments(string[] args)
        {
            foreach (string arg in args)
            {
                string key,value;
                char ch=arg[0];
                bool hasPrefix=((arg[0]=='/')||(arg[0]=='-'));
                int pos=arg.IndexOf(':');
                if (pos==-1)
                {
                    key=hasPrefix?arg.Substring(1):arg;
                    value=null;
                }
                else
                {
                    int startPos=hasPrefix?1:0;
                    key=arg.Substring(startPos,pos-startPos);
                    value=arg.Substring(pos+1);
                }

                List<string> vals;
                if (!_args.TryGetValue(key,out vals))
                    _args.Add(key,vals=new List<string>());
                vals.Add(value);
            }
        }

        internal bool TryGetValue(string key,out string value)
        {
            List<string> vals;
            if (_args.TryGetValue(key,out vals))
            {
                value=vals[0];
                return true;
            }

            value=default(string);
            return false;
        }
    }
}
